//
//  ClassificationViewController.m
//  YL8G
//
//  Created by Liccon Chang on 12-7-17.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "ClassificationViewController.h"
#import "UIButton+Custom.h"
#import "HomeViewController.h"
#import <QuartzCore/QuartzCore.h>

@interface ClassificationViewController(Private)

- (UIButton*)buttonWithOrigin:(CGPoint)origin
                  normalImage:(UIImage*)aImage
            hightlightedImage:(UIImage*)aHightlightedImage
                selectedImage:(UIImage*)aSelectedImage
                          tag:(int)tag
                      caption:(NSString*)caption;
@end

@implementation ClassificationViewController

#pragma mark - View lifecycle
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
    [super loadView];
    
    UIScrollView* scv=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    scv.contentSize=CGSizeMake(self.view.frame.size.width, 410);
    scv.backgroundColor = [UIColor whiteColor];
    self.view = scv;
    [scv release];
    
    self.navigationItem.title=@"分类";
    int x=9;
    int y=4;
    UIButton* classBtn=[self buttonWithOrigin:CGPointMake(x, y)
                                  normalImage:[UIImage imageNamed:@"class1.png"]
                            hightlightedImage:nil
                                selectedImage:nil
                                          tag:EBROKENEWS
                                      caption:@"大家爆料"];
    [self.view addSubview:classBtn];
    
    x=9;
    y=84;
    classBtn=[self buttonWithOrigin:CGPointMake(x, y)
                        normalImage:[UIImage imageNamed:@"class2.png"]
                  hightlightedImage:nil
                      selectedImage:nil
                                tag:EBAGAJW
                            caption:@"八卦江湖"];
    [self.view addSubview:classBtn];
    
    x=9;
    y=164;
    classBtn=[self buttonWithOrigin:CGPointMake(x, y)
                        normalImage:[UIImage imageNamed:@"class3.png"]
                  hightlightedImage:nil
                      selectedImage:nil
                                tag:EFCDP
                            caption:@"灰常点评"];
    [self.view addSubview:classBtn];
    
    x=9;
    y=244;
    classBtn=[self buttonWithOrigin:CGPointMake(x, y)
                        normalImage:[UIImage imageNamed:@"class4.png"]
                  hightlightedImage:nil
                      selectedImage:nil
                                tag:EZSFS
                            caption:@"资深粉丝"];
    [self.view addSubview:classBtn];
    
    x=9;
    y=324;
    classBtn=[self buttonWithOrigin:CGPointMake(x, y)
                        normalImage:[UIImage imageNamed:@"class5.png"]
                  hightlightedImage:nil
                      selectedImage:nil
                                tag:EDTTS
                            caption:@"道听途说"];
    [self.view addSubview:classBtn];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (UIButton*)buttonWithOrigin:(CGPoint)origin
                  normalImage:(UIImage*)aImage
            hightlightedImage:(UIImage*)aHightlightedImage
                selectedImage:(UIImage*)aSelectedImage
                          tag:(int)tag
                      caption:(NSString*)caption
{
    UIButton* retBtn=[UIButton buttonWithOrigin:origin
                                     normalImage:aImage
                               hightlightedImage:aHightlightedImage
                                   selectedImage:aSelectedImage
                                    asBackground:FALSE];
    [retBtn addTarget:self action:@selector(btnPress:) forControlEvents:UIControlEventTouchUpInside];
    retBtn.tag=tag;
    [retBtn setTitle:caption forState:UIControlStateNormal];
    retBtn.layer.shadowOffset= CGSizeMake(1, 1);
    retBtn.layer.shadowRadius= 3.0;
    retBtn.layer.shadowColor= [UIColor blackColor].CGColor;
    retBtn.layer.shadowOpacity= .8f;

    
    UILabel* captionLabel=[[UILabel alloc] initWithFrame:CGRectMake(5, 50, 140, 30)];
    captionLabel.font=[UIFont systemFontOfSize:16];
    captionLabel.text=caption;
    captionLabel.backgroundColor=[UIColor clearColor];
    [retBtn addSubview:captionLabel];
    [captionLabel release];
    return  retBtn;
}

- (void)btnPress:(UIButton*)sender
{
    HomeViewController* homeCtrl = [[HomeViewController alloc] init];
    homeCtrl.categoryId=@"funinfo";
    homeCtrl.categoryName=@"娱乐八卦";
    homeCtrl.isRecommend=FALSE;
    homeCtrl.navigationItem.title=[sender titleForState:UIControlStateNormal];
    homeCtrl.subItem=[sender titleForState:UIControlStateNormal];
    homeCtrl.hidesBottomBarWhenPushed=TRUE;
    [self.navigationController pushViewController:homeCtrl animated:TRUE];
    [homeCtrl release];
}

#pragma mark -
#pragma mark AdSageRecommendDelegate
- (UIViewController *)viewControllerForPresentingModalView
{
    return self.tabBarController;
}

- (void) adSageWillOpenRecommendModalView
{
    
}

- (void) adSageFailToOpenRecommendModalView
{
    NSLog(@"推荐弹出失败");
}

- (void) adSageDidCloseRecommendModalView
{
    NSLog(@"推荐关闭");
}

#pragma mark - View lifecycle
- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)dealloc
{    
    [super dealloc];
}

@end
